//将秒转换为xx分xx秒
const timeFormat = function(str){
  var min =  Math.floor(str/60);
  var sen= str - min*60;
  return  min +'分'+sen+'秒'
}
//将秒格式化为日期

function format (fmt) {
  var o = {
    "M+": this.getMonth() + 1, //月份 
    "d+": this.getDate(), //日 
    "h+": this.getHours(), //小时 
    "m+": this.getMinutes(), //分 
    "s+": this.getSeconds(), //秒 
    "q+": Math.floor((this.getMonth() + 3) / 3), //季度 
    "S": this.getMilliseconds() //毫秒 
  };
  if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  for (var k in o)
    if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
  return fmt;
}


/**========================== */

/**生成随机数*/
const randomStr = (len) => {
  len = len || 32;
  var $chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678';
  var maxPos = $chars.length;
  var pwd = '';
  for (var i = 0; i < len; i++) {
    pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
  }
  return pwd;
}


/**========================== */
// 登录生成图片验证码

const verification = (str) => {
  return "https://api.cloudcpc.com/home/Login/create?id=" + str;
}


/**========================== */
//登录注册验证手机号
const validateTel = (tel) => {
  var TEL_REGEXP = /^1([38]\d|5[0-35-9]|7[3678])\d{8}$/;
  if (TEL_REGEXP.test(tel)) {
    return true;
  }
  return false;
}

//将百分制转化为数字
const percentFormat = function(str){
  return parseInt(str.replace(/%$/,''));
}


module.exports = {
  timeFormat:timeFormat,
  randomStr: randomStr,
  verification: verification,
  validateTel: validateTel,
  percentFormat: percentFormat,
  format: format
 
}
